<?php

namespace app\controller;

use support\Request;
use Webman\RedisQueue\Redis;
use Workerman\Protocols\Http\Session;

class IndexController
{
    /**
     * 不需要登录的方法
     */
    protected $noNeedLogin = ['login', 'register'];

    public function index(Request $request)
    {
        return view("index/index");
    }

    public function view(Request $request)
    {
        return view('index/view', ['name' => 'a']);
    }

    public function json(Request $request)
    {
        return json(['code' => 0, 'msg' => 'ok']);
    }

    public function queue(Request $request)
    {
        // 队列名
        $queue = 'send-mail';
        // 数据，可以直接传数组，无需序列化
        $data = ['to' => 'tom@gmail.com', 'content' => 'hello'];
        // 投递消息
        Redis::send($queue, $data);
        // 投递延迟消息，消息会在60秒后处理
        Redis::send($queue, $data, 60);

        return response('redis queue test');
    }

    public function register()
    {
        return view('index/register');
    }

    public function login()
    {
        return view('index/login');
    }

    public function exit()
    {
        try {
            session()->forget('login_user');
        } catch (\Exception $e) {
            return jsonFail(100, $e);
        }
        return view('index/login');
    }


    public function test(Request $request)
    {
        return view('index/panel');
    }
}
